var express = require('express');
var template = require('art-template')

var app = express();

template.config('extname', '.html');
app.engine('.html', template.__express);
app.set('view engine', 'html');
app.set('views', __dirname + '/views');

app.get('/', function(req, res){
  res.render('./streams',{title:'SSE'});
});

app.get('/stream', function(req, res){
    res.writeHead(200, {"Content-Type":"text/event-stream"});
    res.write("event: connect\n");

    var interval = setInterval(function() {
		console.log(new Date())
		res.write("data: " + (new Date()) + "\n\n");
    }, 1000);
	
    req.connection.addListener("close", function () {
      clearInterval(interval);
    }, false);

});

app.listen(80)